package com.ydw.hessian;

import com.caucho.hessian.io.HessianInput;
import com.caucho.hessian.io.HessianOutput;
import com.sun.xml.internal.messaging.saaj.util.ByteInputStream;
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
import com.ydw.model.Person;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
 * Created by ydw on 2017/7/5.
 */
public class HessianTest {
    public static void main(String[] args) throws IOException {
        Person person = new Person();
        person.setAge(18);
        person.setName("ydw");
        person.setId(1L);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        HessianOutput hessianOutput = new HessianOutput(byteArrayOutputStream);
        //序列化
        hessianOutput.writeObject(person);
        byte[] bytes = byteArrayOutputStream.toByteArray();
        //反序列化
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
        HessianInput hessianInput = new HessianInput(byteArrayInputStream);
        Person ydw = (Person) hessianInput.readObject();
        System.out.println(ydw);
    }
}
